<?php
    class db
    {
        private $hostname;
        private $username;
        private $password;
        private $database;
        private $connect;
        private $select_db;

        public function db(){
            $this->hostname = "localhost";
            $this->username = "root";
            $this->password = "";
            $this->database = "user_message";
        }

        private function open_connection(){
            $this->connect = mysql_connect($this->hostname,$this->username,$this->password);
            if(!$this->connect){
                die("Couldn't connect to database server");
            }
            $this->select_db = mysql_select_db($this->database);
            if(!$this->select_db){
                die("Couldn't connect to database");
            }
        }

        private function close_connection(){
            $result = mysql_close($this->connect);
            if(!$result){
                echo("Error while closing the connection to database");
            }
        }

        public function query($query){
            $result = null;
            $this->open_connection();
            $result = mysql_query($query);
            $this->close_connection();
            return $result;
        }
    }
?>
